package com.yanqu.road.server.cmd.activity.daomu.pvp;

import com.yanqu.road.entity.activity.daomu.config.DaoMuActivityConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DaoMuPvpProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.daomu.DaoMuActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_DAOMU_PVP_ENTER_NEXT_FLOOR, desc = "进入下一层")
public class DaoMuPvpEnterNextFloorCmd extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DaoMuPvpProto.DaoMuPvpEnterNextFloorReqMsg reqMsg = DaoMuPvpProto.DaoMuPvpEnterNextFloorReqMsg.parseFrom(packet.getBytes());
        //获取活动配置
        DaoMuActivityConfig config = DaoMuActivityMgr.getActivityConfig(reqMsg.getActivityId());
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST;
            return;
        }
        // 直接上跨服
        player.sendPacket(Protocol.C_CROSS_DAOMU_PVP_ENTER_NEXT_FLOOR, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            DaoMuPvpProto.DaoMuPvpEnterNextFloorRespMsg.Builder respMsg = DaoMuPvpProto.DaoMuPvpEnterNextFloorRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_DAOMU_PVP_ENTER_NEXT_FLOOR, respMsg);
        }
    }
}
